from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.urls import reverse
from .models import Player

def check_player_and_lost(view_func):
    """checks for new player, lost and no acc"""
    def check(request, *args, **kwargs):
        # new player
        try:
            player = Player.objects.get(pk=request.user)
        except Player.DoesNotExist:
            return HttpResponseRedirect(reverse("zylinder_app:newPlayer"))
        # lost
        if player.lost:
            return HttpResponseRedirect(reverse("zylinder_app:youLost"))
        else:
            return view_func(request, *args, **kwargs)
    return check

# here we could also add @need_player
